package com.jbit.examSystem.controller;

import com.jbit.examSystem.pojo.Class;
import com.jbit.examSystem.pojo.Grade;
import com.jbit.examSystem.pojo.Teacher;
import com.jbit.examSystem.service.ClassService;
import com.jbit.examSystem.service.ExamService;
import com.jbit.examSystem.service.GradeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@Controller
@RequestMapping("skip")
public class SkipController {
    @Autowired
    private GradeService gradeService;
    @Autowired
    private ExamService examService;
    @Autowired
    private ClassService classService;

    //试卷管理页面
    @RequestMapping("testPaperManager")
    public String testPaperManager(){

        return "onlineExam/testPaper/testPaper";
    }

    //试题管理页面
    @RequestMapping("questionManager")
    public String questionManager(Model model){

        List<Grade> grades = gradeService.getAllGrade();
        model.addAttribute("grades",grades);

        return "onlineExam/question/question";
    }

    //科目管理页面
    @RequestMapping("courseManager")
    public String subjectManager(Model model){


        List<Grade> grades = gradeService.getAllGrade();
        model.addAttribute("grades",grades);

        return "onlineExam/course/course";
    }

    //考试管理页面
    @RequestMapping("examManager")
    public String examManager(Model model){
        Integer i = null;
        List<Class> classes = classService.getAllClass(i);
        model.addAttribute("classes",classes);
        return "onlineExam/exam/exam";
    }

    @RequestMapping("skipReview")
    public String skipReview(HttpServletResponse response){
        response.setCharacterEncoding("UTF-8");
        try (PrintWriter writer = response.getWriter()) {
            writer.write("<script>location.href='/exam/createExamPage?examId=10001';</script>");
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
    @RequestMapping("ranking")
    public String ranking(){
        return "ranking/ranking";
    }

    @RequestMapping("examResult")
    public String examResult(Model model){

        List<Grade> grades = gradeService.getAllGrade();

        model.addAttribute("grades",grades);

        return "onlineExam/examResult/exam";
    }
    @RequestMapping("examResult2")
    public String examResult2(Model model){
        List<Grade> grades = gradeService.getAllGrade();

        model.addAttribute("grades",grades);

        return "onlineExam/examResult/exam2";
    }

    @RequestMapping("history")
    public String skipHistory(){
        return "history/history";
    }

    @RequestMapping("log")
    public String log(){
        return "system/log/log";
    }

    @RequestMapping("user")
    public String user(){
        return "system/user/user";
    }

    @RequestMapping("notice")
    public String notice(){
        return "system/notice/notice";
    }
}
